﻿using System;
using System.ComponentModel;
using System.Windows.Data;
using System.Windows.Media.Imaging;

using Data;
using MSAP.Framework;
using MSAP.Framework.Interfaces;

namespace PLL.Notes
{
    public class NotesServicePage : ServicePageBase
    {
        public NotesServicePage(NotesModule module)
            :base("NOTES.NOTES_SP","Notes",
                new Uri("/PLL.Notes;component/Pages/NotesPage.xaml", UriKind.Relative),"Notes", 
                new BitmapImage(new Uri("/PLL.Notes;component/Resources/Notes.png", UriKind.Relative)))
        {
            Init(module);
        }

        public override void Init(IModule module)
        {
            base.Init(module);

            ServiceActions.Add(new NoteAdd_SAC(this));
            ServiceActions.Add(new NoteDelete_SAC(this));
            ServiceActions.Add(new NoteSave_SAC(this));
            ServiceActions.Add(new NoteLoad_SAC(this));
        }

        #region Properties
        public NotesModule NotesModule
        {
            get 
            {
                return Module as NotesModule;
            }
        }

        public NoteSet TableNotes
        {
            get
            {
                return NotesModule.TableNotes;
            }
        }

        public ICollectionView RecordsView
        {
            get
            {
                if (m_RecordsView == null)
                {
                    m_RecordsView = CollectionViewSource.GetDefaultView(TableNotes.Records);
                    m_RecordsView.MoveCurrentToFirst();
                }
                return m_RecordsView;
            }
            set
            {
                m_RecordsView = value;
            }
        }

        #endregion Properties

        #region fields
        ICollectionView m_RecordsView;
        #endregion fields
    }
}
